//
//  NewestRecommend.m
//  AutoHome
//
//  Created by wqh on 15-5-10.
//  Copyright (c) 2015年 Wqh. All rights reserved.
//

#import "NewestRecommend.h"
#import "RecommendModel.h"
#import "RecommendCell.h" 
#import "RecommendPicCell.h"
#import "RecommendHeaderView.h"

#import "RecommendNormalDetail.h"
#import "NewsflashRecommendDetail.h"
#import "RecommendPicsDetail.h"

#import "QFRefreshView.h"

#define NewestRecommendCellID_6 @"RecommendPicCellId"
@interface NewestRecommend ()

@end

@implementation NewestRecommend

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createTableView];
    [self createHeaderView];
    [self downloadData];
    [self createRefreshView];
}


//创建头部滚动视图
- (void)createHeaderView {
    NSString *url = [NSString stringWithFormat:self.info[@"url"],1,@"0"];
    RecommendHeaderView *headerView = [[RecommendHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 160) Url:url];
    self.tableView.tableHeaderView = headerView;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    RecommendModel *model = self.dataArr[indexPath.row];
    if ([model.mediatype.stringValue isEqualToString:@"6"]) {
        RecommendPicCell *cell = [tableView dequeueReusableCellWithIdentifier:NewestRecommendCellID_6];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"RecommendPicCell" owner:self options:nil] lastObject];
        }
        [cell showDataWithModel:model];
        return cell;
    }else {
        RecommendCell *cell = [tableView dequeueReusableCellWithIdentifier:RecommendCellId];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"RecommendCell" owner:self options:nil] lastObject];
            
        }
        [cell showDataWithModel:model type:YES];
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    
    RecommendModel *model = self.dataArr[indexPath.row];
    
   
    
    if ([model.mediatype.stringValue isEqualToString:@"6"] ) {
        RecommendPicsDetail *picsView = [RecommendPicsDetail new];
        picsView.model = model;
//        self.myPageJumpBlcok(picsView);
        if (self.myJumpBlcok) {
            self.myJumpBlcok(picsView);
        }
        self.myHiddeTabBarBlock(YES);
        return ;
    }
    if ([model.mediatype.stringValue isEqualToString:@"7"] ) {
        NewsflashRecommendDetail *newsflashView = [NewsflashRecommendDetail new];
        newsflashView.model = model;
        self.myPageJumpBlcok(newsflashView);
        self.myHiddeTabBarBlock(YES);
        return ;
    }
    
    RecommendNormalDetail *vc = [RecommendNormalDetail new];
    if ([model.mediatype.stringValue isEqualToString:@"2"]) {
        vc.url = kRecommendDetailPersuaderUrl;
    }
    if([model.mediatype.stringValue isEqualToString:@"3"]) {
        vc.url  = kRecommendDetailVideoUrl;
    }
    if ([model.mediatype.stringValue isEqualToString:@"5"] ) {
        vc.url   = kRecommedDetailPostUrl    ;
    }
    
    vc.model = model;
    

    
    if (self.myPageJumpBlcok) {
        self.myPageJumpBlcok(vc);
    }
    if (self.myHiddeTabBarBlock) {
        self.myHiddeTabBarBlock(YES);
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
